// 战斗操作层

var BattleTouchPanel = DraggablePanelBase.extend({

    //onTouchBegan:function (touch, event) { cc.log('MUST override this function:onTouchBegan'); },
    //onTouchMoved:function (touch, event) { cc.log('MUST override this function:onTouchMoved'); },
    //onTouchEnded:function (touch, event) { cc.log('MUST override this function:onTouchEnded'); },
    //onTouchCancelled:function (touch, event) { cc.log('MUST override this function:onTouchCancelled'); },

    // 点击
    onTouchBegan:function (touch, event) {
        var tpos = touch.getLocation();

        if(this._isTouchIn(tpos)) {
            var cp = this._touchPos2Cell(tpos);
            return BattleLayer.onClick(cp.x, cp.y);
        }
        return false;
    },

    onTouchEnded:function (touch, event) {
        
    },


    // 点击在范围内 只要下面就行了
    _isTouchIn : function (touchPos) {
        var p = cc.pSub(touchPos, helper.CELLS_DOWN_BASE);
        return (p.x >= 0 && p.x < helper.GARAGE_WIDTH && p.y <= 0 && p.y > -helper.GARAGE_HEIGHT);
    },

    // touch坐标转成Cell坐标
    _touchPos2Cell : function (touchPos) {
        var p = cc.pSub(touchPos, helper.CELLS_DOWN_BASE);
        var cx = parseInt(p.x / helper.CELL_SIZE);
        var cy = -parseInt(p.y / helper.CELL_SIZE);
        return cc.p(cx, cy);
    }, 

});

